const Router = require('@koa/router');
const routesController = require('../controllers/routesController');

const router = new Router({ prefix: '/routes' });

// 获取推荐路线列表
/**
 * @swagger
 * /routes/recommendations:
 *   get:
 *     summary: 获取推荐路线列表
 *     parameters:
 *       - in: query
 *         name: category
 *         schema:
 *           type: string
 *         description: 路线类别
 *       - in: query
 *         name: keyword
 *         schema:
 *           type: string
 *         description: 关键字搜索
 *     responses:
 *       200:
 *         description: 成功获取推荐路线列表
 *       500:
 *         description: 获取失败
 */
router.get('/recommendations', routesController.getRecommendations);

// 获取路线详情
/**
 * @swagger
 * /routes/{id}:
 *   get:
 *     summary: 获取路线详情
 *     parameters:
 *       - in: path
 *         name: id
 *         schema:
 *           type: integer
 *         required: true
 *         description: 路线ID
 *     responses:
 *       200:
 *         description: 成功获取路线详情
 *       500:
 *         description: 获取失败
 */
router.get('/:id', routesController.getRouteById);

// 创建自定义旅游路线
/**
 * @swagger
 * /routes/create:
 *   post:
 *     summary: 创建自定义旅游路线
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               name:
 *                 type: string
 *               description:
 *                 type: string
 *               category:
 *                 type: string
 *               estimated_time:
 *                 type: string
 *               rating:
 *                 type: number
 *               spots:
 *                 type: array
 *                 items:
 *                   type: object
 *                   properties:
 *                     id:
 *                       type: integer
 *                     name:
 *                       type: string
 *                     location:
 *                       type: string
 *                     image:
 *                       type: string
 *     responses:
 *       201:
 *         description: 成功创建自定义旅游路线
 *       500:
 *         description: 创建失败
 */
router.post('/create', routesController.createRoute);

// 更新旅游路线
/**
 * @swagger
 * /routes/update/{id}:
 *   put:
 *     summary: 更新旅游路线
 *     parameters:
 *       - in: path
 *         name: id
 *         schema:
 *           type: integer
 *         required: true
 *         description: 路线ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               name:
 *                 type: string
 *               description:
 *                 type: string
 *               category:
 *                 type: string
 *               estimated_time:
 *                 type: string
 *               rating:
 *                 type: number
 *               spots:
 *                 type: array
 *                 items:
 *                   type: object
 *                   properties:
 *                     id:
 *                       type: integer
 *                     name:
 *                       type: string
 *                     location:
 *                       type: string
 *                     image:
 *                       type: string
 *     responses:
 *       200:
 *         description: 成功更新旅游路线
 *       500:
 *         description: 更新失败
 */
router.put('/update/:id', routesController.updateRoute);

// 删除旅游路线
/**
 * @swagger
 * /routes/delete/{id}:
 *   delete:
 *     summary: 删除旅游路线
 *     parameters:
 *       - in: path
 *         name: id
 *         schema:
 *           type: integer
 *         required: true
 *         description: 路线ID
 *     responses:
 *       200:
 *         description: 成功删除旅游路线
 *       500:
 *         description: 删除失败
 */
router.delete('/delete/:id', routesController.deleteRoute);

// 用户自定义路线排序
/**
 * @swagger
 * /routes/sort:
 *   post:
 *     summary: 用户自定义路线排序
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               route_id:
 *                 type: integer
 *               spots_order:
 *                 type: array
 *                 items:
 *                   type: integer
 *     responses:
 *       200:
 *         description: 成功排序用户自定义路线
 *       500:
 *         description: 排序失败
 */
router.post('/sort', routesController.sortRouteSpots);

module.exports = router;
